<template>
	<div>
		<div v-if="btn">
			<el-select size="mini" v-model="type" placeholder="请选择" style="float: left;padding-right: 10px;">
				<el-option v-for="dict in types" :key="dict.dictValue" :label="dict.dictLabel" :value="dict.dictValue"></el-option>
			</el-select>
			<el-button type="primary" size="mini" @click="importOpen">上传文件</el-button>
		</div>
		<div>
			<el-divider content-position="left">健康信息</el-divider>
			<el-image v-for="item in heaithList" style="width: 100px; height: 100px;padding-right: 5px;" :src="item.url"></el-image>
			<el-divider content-position="left">学历信息</el-divider>
			<el-image v-for="item in educationList" style="width: 100px; height: 100px;padding-right: 5px;" :src="item.url"></el-image>
			<el-divider content-position="left">资质证书</el-divider>
			<el-image v-for="item in certificateList" style="width: 100px; height: 100px;padding-right: 5px;" :src="item.url"></el-image>
		</div>
		<ImportPage ref="importPage" :title="'附件'" :uploadData="{'type':type}" :importUrl="importUrl" @onSuccess="onSuccess" />
	</div>
</template>

<script>
	import { listSysUserEnclosure, userEnclosureUpload } from "@/api/system/userEnclosure";
	import { validatenull } from '@/utils/validate'
	import { getToken } from "@/utils/auth";
	import { openMsgs, openNotify } from '@/utils/util';

	export default {
		props: {
			userModel: {
				type: Object
			},
			btn: {
				type: Boolean
			}
		},
		data() {
			return {
				importUrl: userEnclosureUpload(),
				type: '',
				types: [],
				queryParams: { // 查询参数
					userId: null
				},
				heaithList: [],
				educationList: [],
				certificateList: [],
			}
		},
		created() {
			this.queryParams.userId = this.userModel.userId
			this.getDicts("enclosure_type").then(response => {
				this.types = response.data;
			});
			this.getUserEnclosureList();
		},
		methods: {
			getUserEnclosureList() {
				listSysUserEnclosure(this.queryParams).then(response => {
					let data = response.rows;
					this.heaithList = []
					this.educationList = []
					this.certificateList = []
					for(let d of data) {
						if(d.type == '1') {
							this.heaithList.push(d)
						} else if(d.type == '2') {
							this.educationList.push(d)
						} else if(d.type == '3') {
							this.certificateList.push(d)
						}
					}
				});
			},
			importOpen() {
				if(validatenull(this.type)) {
					openNotify(this, '上传附件', '请选择附件类型', true, 'error');
					return false
				}
				this.$refs.importPage.initStatus(true);
			},
			onSuccess() {
				this.$refs.importPage.clearStatus();
				this.getUserEnclosureList()
			},
		},
	};
</script>